<?php

namespace App\Http\Requests;

use App\Http\Requests\Request;

class UserCreateRequest extends Request
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'name' => 'required|unique:users,name|regex:/^\w{6,20}$/',
            'password' => 'required|regex:/^\S{6,20}$/|same:repassword',
            'email'=>'required|email'
        ];
    }
    /**
     * 自定义错误信息
     */
    public function messages()
    {
        return [
            'name.required'=>'用户名必填',
            'name.unique'=>'用户名已经存在',
            'name.regex'=>'用户名格式不正确',
            'password.required'=>'密码必填',
            'password.regex'=>'密码格式不正确',
            'password.same'=>'两次输入密码不同',
            'email.required'=>'邮箱必填',
            'email.email'=>'请填写正确的邮箱'
        ];
    }
}
